﻿
var sys = {};
var navua = navigator.userAgent.toLowerCase();
var browser;
(browser = navua.match(/msie ([\d.]+)/)) ? sys.ie = browser[1] :
(browser = navua.match(/firefox\/([\d.]+)/)) ? sys.firefox = browser[1] :
(browser = navua.match(/chrome\/([\d.]+)/)) ? sys.chrome = browser[1] :
(browser = navua.match(/opera.([\d.]+)/)) ? sys.opera = browser[1] :
(browser = navua.match(/version\/([\d.]+).*safari/)) ? sys.safari = browser[1] : 0;

function checkip(ipvalue)
{
	var pattern=/^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
	flag_ip=pattern.test(ipvalue);
	if(!flag_ip)
	{	 
		 	hiAlert('IP地址格式错误！格式应为:[192.168.0.1]', '请注意');
			return false;
	}
}
 

 function checkeUserName(str) { 
var pattern_cn = /^([\u4E00-\u9FA5]|[\uFE30-\uFFA0]|[_\a-zA-Z0-9]|[\s])*$/gi; 
if(pattern_cn.test(str)) 
{ return true; } 
 else 
{ return false; } 
} 
 //校验普通电话、传真号码：可以“+”开头，除数字外，可含有“-”   
  function   isTel(s)   
  {   
  //var   patrn=/^[+]{0,1}(\d){1,3}[   ]?([-]?(\d){1,12})+$/;   
  var   patrn=/^[+]{0,1}(\d){1,3}[   ]?([-]?((\d)|[   ]){1,12})+$/;   
  if   (!patrn.exec(s))   return   false   
  return   true   
  }   
    
  //校验手机号码：必须以数字开头，除数字外，可含有“-”   
  function   isMobil(s)   
  {   
  var   patrn=/^[+]{0,1}(\d){1,3}[   ]?([-]?((\d)|[   ]){1,12})+$/;   
  if   (!patrn.exec(s))   {
  return   false ; 
	} else  { 
		if (s.length<11) {return   false;} else { return   true;  }
 
	} 
  }   
    
  //校验邮政编码   
  function   isPostalCode(s)   
  {   
  //var   patrn=/^[a-zA-Z0-9]{3,12}$/;   
  var   patrn=/^[a-zA-Z0-9   ]{3,12}$/;   
  if   (!patrn.exec(s))   return   false   
  return   true   
  }   
    
  //校验搜索关键字   
  function   isSearch(s)   
  {   
  var   patrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;\'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;\'\,.<>?]{0,19}$/;   
  if   (!patrn.exec(s))   return   false   
  return   true   
  }   
   //
  function   isNumeric(s)   
  {   
  var   patrn=/^-?\d+\.?\d*$/;   
  if   (!patrn.exec(s))   return   false   
  return   true   
  }      
 
function removeAllSpace(str) {
  return str.replace(/\s+/g, "");
}

 
 
//+---------------------------------------------------
//|	快速方法获得当前的对象
//+---------------------------------------------------
function $byid(objectId){
	return reobj=(typeof(objectId)=="object") ? objectId : document.getElementById(objectId);
}
//+---------------------------------------------------
//|	操作cookie的方法
//@Author: johnson
//+---------------------------------------------------
function getCookie(name) {
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null){
		if (unescape(arr[2]) == null){
			return ;
		}else{
			return unescape(arr[2]);
		}
		
	}else{
		return ;
	}
}

function setCookie(name,value) {
	var Days = 30; //此 cookie 将被保存 30 天
	var exp  = new Date();    //new Date("December 31, 9998");
	exp.setTime(exp.getTime() + Days*24*60*60*1000);

	//document.cookie = name + "="+value+ ";path=/;expires=" + exp.toGMTString();
	document.cookie = name + "="+ escape (value) + ";path=/;expires=" + exp.toGMTString();

}

function delCookie(name){
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=getCookie(name);
	if(cval!=null) document.cookie= name + "="+cval+";path=/;expires="+exp.toGMTString();
}

/*以json的形式写入数组cookie*/
function setjsonCookie(name,value){
	//alert(name);
	//alert(value);
	var co = json_encode(value);
	setCookie(name,co);
}

/*以json的形式读取数组cookie*/
function getjsonCookie(name){
	var co = getCookie(name);
	//alert(json_decode(co));
	if(co!=null){
		co = co.replace(/,_/g, ',');
		co = co.replace(/{_/g, '{');
		co = co.replace(/_}/g, '}');
		return json_decode(co);
	}else{
		return false;
	}

}

/*以删除所有cookie*/
function clearCookie()
{
	var strCookie=document.cookie;
	var arrCookie=strCookie.split("; "); // 将多cookie切割为多个名/值对
	for(var i=0;i <arrCookie.length;i++)
	{ // 遍历cookie数组，处理每个cookie对
		var arr=arrCookie[i].split("=");
		if(arr.length>0)
		delCookie(arr[0]);
	}
}


function delCookie(name){
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=getCookie(name);
	if(cval!=null) document.cookie= name + "="+cval+";path=/;expires="+exp.toGMTString();
}

/*以json的形式写入数组cookie*/
function setjsonCookie(name,value){
	//alert(name);
	//alert(value);
	var co = json_encode(value);
	setCookie(name,co);
}

/*以json的形式读取数组cookie*/
function getjsonCookie(name){
	var co = getCookie(name);
	//alert(json_decode(co));
	if(co!=null){
		co = co.replace(/,_/g, ',');
		co = co.replace(/{_/g, '{');
		co = co.replace(/_}/g, '}');
		return json_decode(co);
	}else{
		return false;
	}

}

/*以删除所有cookie*/
function clearCookie()
{
	var strCookie=document.cookie;
	var arrCookie=strCookie.split("; "); // 将多cookie切割为多个名/值对
	for(var i=0;i <arrCookie.length;i++)
	{ // 遍历cookie数组，处理每个cookie对
		var arr=arrCookie[i].split("=");
		if(arr.length>0)
		delCookie(arr[0]);
	}
}




/* jt mouseover & mouseout */
function showTip(id){
	$("#"+id).mouseover(function(){
		var self = $(this).attr("id");
		jt(self);
		var _jtc = $(this).attr("jtContent");
		$("#jtContent").html(_jtc);
	}).mouseout(function(){
		$("#jt").remove();
	});
}

/*
 * Javascript Tips(jt)
 *
 * 作用：仅处理获取父级私有属性值后并赋予自身。
 *
 * 提示：
 * 1. 需要以一个事件来触发jt()
 * 2. 以id作为唯一标示传给jt()
 * 3. 必需加的属性 jtTitle="" jtWidth=""，当需要ajax某个页面的时候，可选属性 jtURL=""(该属性有待修改)
 * 4. #jt 是插入层的id，别冲突了

 * BidTip Example:

	$(document).ready(function(){
		$(".jtMO").mouseover(function(){
			var self = $(this).attr("id");
			jt(self);
		}).mouseout(function(){
			$("#jt").remove();
		});
	});

	<a id="ajaxTip2" href="/" jtURL='__APP__/User/getcount/' jtTitle="客服中心" jtWidth="250" class="jtMO">JT提示</a>

	<span jtTitle="提示" jtWidth="350" id="ajaxTip3" class="button jtBid">
		<span class="first-child">
			<button type="button" class="strong">出 价</button>
		</span>
	</span>

*/
function jt(objId)
{
	var de = document.documentElement;
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;

	var hasArea = w - getAbsoluteLeft(objId);

	var clickElementy = getAbsoluteTop(objId) - 3;

	var $self = $("#" + objId);
	var _u = $self.attr("jtURL");
	var _t = $self.attr("jtTitle");
	var _w = $self.attr("jtWidth");
	var _c = $self.attr("jtContent");
  // alert(_w);
	var jtArray = {"url":_u,"title":_t,"width":_w,"content":_c};
	// alert(_url);
	//
	var _url = jtArray.url;
	
	if(_url === undefined)
	{
		_url = "";
	}
	else
	{
		$.ajax({
			type: "POST",
			url:_url,
			dataType: "html",
			success: function(msg){
				$("#jtContent").html(msg);
			}
		});
	}
	
	//
	var _content = jtArray.content;
	//alert(_content);
	if(_content === undefined){_c = "";}
	if(hasArea>((jtArray.width*1)+75))
	{
		$("body").append("<div id='jt' style='display:none; width:"+jtArray.width*1+"px'><div id='jtArrowL'></div><div id='jtTitleL'>"+jtArray.title+"</div><div id='jtContent'><div id='jtLoader'><div></div></div>");
		var arrowOffset = getElementWidth(objId) + 11;
		var clickElementx = getAbsoluteLeft(objId) + arrowOffset;
	}
	else
	{
		$("body").append("<div id='jt' style='display:none; width:"+jtArray.width*1+"px'><div id='jtArrowR' style='left:"+((jtArray.width*1)+1)+"px'></div><div id='jtTitleR'>"+jtArray.title+"</div><div id='jtContent'><div id='jtLoader'><div></div></div>");
		var clickElementx = getAbsoluteLeft(objId) - ((jtArray.width*1) + 15);
	}
//alert(clickElementx);
	$('#jt').css({left:clickElementx+"px", top:clickElementy+"px"}).fadeIn("fast");

	//Get width
	function getElementWidth(objId)
	{
		var x = $byid(objId);
		return x.offsetWidth;
	}

	//Get left position from the parent object
	function getAbsoluteLeft(objId)
	{
		var o = $byid(objId);
		var oLeft = o.offsetLeft;
		while(o.offsetParent!=null)
		{
			oParent = o.offsetParent;
			oLeft += oParent.offsetLeft;
			o = oParent;
		}
		return oLeft;
	}

	//Get top position from the parent object
	function getAbsoluteTop(objId)
	{
		var o = $byid(objId);
		var oTop = o.offsetTop;
		while(o.offsetParent!=null)
		{
			oParent = o.offsetParent;
			oTop += oParent.offsetTop;
			o = oParent;
		}
		return oTop;
	}
}


/* scaling in proportion */
function drawImage(obj,w,h)
{
	var image = new Image();
	image.src = obj.src;
	
	if(image.width>0 && image.height>0)
	{
		flag = true;
		if(image.width/image.height >= w/h)
		{
			if(image.width > w)
			{
				obj.width = w;
				obj.height = (image.height*w)/image.width;
			}
			else
			{
				obj.width = image.width;
				obj.height = image.height;
			}
		}
		else
		{
			if(image.height > h)
			{
				obj.height = h;
				obj.width = (image.width*h)/image.height;
			}
			else
			{
				obj.width = image.width;
				obj.height = image.height;
			}
		}
	}
}

function showBidTip(id,text){
	//alert(id);
	//alert($("#"+id).parent().attr("id")); //alert($("#"+id).parent().parent().attr("id"));
	//alert($("#"+id).parent().attr("id"));
	jt($("#"+id).parent().attr("id"));
	
	$("#jtContent").html(text);

	function showJT(){
		$("#jt").fadeOut("fast",function(){
			$(this).remove();
		});
	}

	var tt = window.setTimeout(showJT, 1500);
	$("#jt").hover(
	function(){
		window.clearTimeout(tt);
	},
	function(){
		tt = window.setTimeout(showJT, 1000);
	});

	$("#jt").blur(function(){
		showJT();
	});
}

function Pause(obj,iMinSecond){ 
    if (window.eventList==null) window.eventList=new Array(); 
    var ind=-1; 
    for (var i=0;i<window.eventList.length;i++){ 
     if (window.eventList[i]==null) { 
      window.eventList[i]=obj; 
      ind=i; 
      break; 
     } 
    }

    if (ind==-1){ 
     ind=window.eventList.length; 
     window.eventList[ind]=obj; 
    } 
    setTimeout("GoOn(" + ind + ")",3000); 
    }
    function GoOn(ind){ 
    var obj=window.eventList[ind]; 
    window.eventList[ind]=null; 
    if (obj.NextStep) obj.NextStep(); 
    else obj(); 
    }
function delayRun(code,time) {
   var t=setTimeout(code,time);
   }
function runToParentUrl(url)
{ 
  parent.location = url;
}
function runToSelfUrl(url)
{
  self.location = url;
}






/* 屏幕遮罩 */
function addScreenMask()
{
	var screenMask = '<div id="screenMask" style=" position:absolute; z-index:10000; top:0; left:0; display:none; width:100%; background:#000; opacity:0.8; filter:alpha(opacity=80);"></div>';
	$(document.body).prepend(screenMask);
	$("#screenMask").height($(document).height()).fadeIn("fast");
	$('embed, object, select').css({ 'visibility' : 'hidden' });

}

function removeScreenMask()
{
	$("#screenMask").fadeOut("fast",function(){
		$(this).remove();
	});
	$('embed, object, select').css({ 'visibility' : 'visible' });
}

function quitScreenMask(obj)
{
	$("#screenMask").bind("click", function(){
		removeScreenMask();
		$(obj).fadeOut("fast", function(){
			$(this).remove();
		});
	});
}


/* 对话框 内容嵌入到 .dialogboxContent */
function addDialogbox(objId,title,zIndex,objWidth)
{
	addScreenMask();

	var objIdInHTML = objId.replace(/#/,"");
	var sTop = (document.compatMode == "CSS1Compat") ? document.documentElement.scrollTop : document.body.scrollTop;
 
	//why document.body.scrollTop == 0 on chrome?
 
	if (sys.chrome){sTop = document.body.scrollTop;}
 
	var docBodyScrollTop = sTop + $(window).height()/7;
	var left = $(window).width()/2 - objWidth/2;
 
	$(document.body).prepend
	(
		'<div id='+objIdInHTML+' class="dialogbox skin" style="top:'+docBodyScrollTop+'px; left:'+left+'px; z-index:'+zIndex+'; width:'+objWidth+'px;">'+
			'<div class="dialogboxTitle clearfix">'+'<h2>'+title+'</h2>'+
				'<p>'+
				'<a class="closeDialogbox" href="javascript:void(0);" title="关闭"><img class="sprite sprite_close" src="images/closewindows.png" alt="关闭" /></a>'+
				'</p>'+
			'</div>'+
	         
			'<div class="dialogboxContent" style="height:500px;">'+
				'<iframe id="TencentLogin" name="TencentLogin" style="width:100%;height:200px;" src="about.php">'+
					'<img src="images/loadingAnimation.gif" />'+
				'</iframe>'+
			'</div>'+
		'</div>'
	);
 
	$(objId).fadeIn("fast");

	$(objId+" .closeDialogbox").bind("click",function()
	{
		removeDialogbox(objId);
	});
	
	$("#screenMask").bind("click", function()
	{
	   removeDialogbox(objId);
	});
	
	$("#"+objIdInHTML)
		.bind('dragstart',function( event )
		{
			return $(event.target).is(".dialogboxTitle");
		})
		
		.bind("drag",function( event )
		{
			$( this ).css(
			{
				top: event.offsetY,
				left: event.offsetX
			});
		});		
}

function removeDialogbox(objId)
{
	$(objId).fadeOut("fast",function(){
		removeScreenMask();
		$(this).remove();
		$("html").removeClass("hidden");
	});
}

function ShowRemark(UID)
{
   //oauth/redirect_to_login.php
      //document.domain = 'qq.com';
	addDialogbox('#qqloginwindow','未通过审核原因',100001,600);
	//document.domain = 'eeleer.com';
 //$("#qqloginwindow .dialogboxContent").load("oauth/redirect_to_login.html");
//http://www.eeleer.com/oauth/redirect_to_login.php
//$("#qqloginwindow .dialogboxContent").prepend('12312222');
/*$.ajax({
  type: 'POST',
  url: 'oauth/redirect_to_login.php',
  cache:false,
  data: data,
  success:  function(msg){ $("#qqloginwindow .dialogboxContent").prepend(msg);},
  dataType:'html'
});
		$.get("Test/testphp.php", function(msg){
				       alert(msg);
					$("#qqloginwindow .dialogboxContent").prepend(msg);
				
			},"html");*/
}

function checkuserinfo()
{
	value=$("#txtusername").attr("value");
	if (value=="") {
		hiAlert('请输入用户名称！', '请注意');
		$("#txtusername").focus();
		return false;
	}	
	value=$("#txtpassword").attr("value");
	if (value=="") {
		hiAlert('请输入密码！', '请注意');
		$("#txtpassword").focus();
		return false;
	}	
   var queryString = "";                      
   queryString+= "username=";
   queryString+=$("#txtusername").attr("value");
   queryString+="&password=";
   queryString+=$("#txtpassword").attr("value");         
   queryString+="&varifyID=";
   queryString+=$("#txtVarifyIDS").attr("value");
   
   //alert (queryString);
   	
   $.post("epassword.php",queryString,function(msg){
   	
   	if (msg==-1)
   	  {	hiAlert('输入校验码错误！', '请注意');
   	  	$("#txtVarifyIDS").focus();
   	  	return false;
   	  }
   	if (msg==0)   
   	  {	hiAlert('输入用户名或密码不正确！', '请注意');
   	  	$("#txtusername").focus();
   	  	return false;
   	  }  
   	if (msg==1)   
   	  {	hiAlert('输入用户名或密码正确！', '请注意');
   	  	return true;
   	  }   
   	hiAlert (msg,'good')   	   	
  })        				
}
function getusername(){

	value=$("#txtuserid").attr("value");
	
	if (value=="") {
		hiAlert('请输入用户编号！', '请注意');
		$("#txtuserid").focus();
		return false;
	}	

	var queryString = "";                      
	queryString+= "id=";
	queryString+=$("txtuserid").attr("value");
     
	$.post("getusername.php",queryString ,function(msg){
		alert(msg);
		$("#txtusername").attr("value",msg);
        }) 	  
}

function cleartxt()
{
	$("#txtusername").attr("value","");
	$("#txtpassword").attr("value","");
	$("#txtusername").focus();
}

function forgotpassword(){
       if( $("#txtemail").attr("value")=="" ){
				  hiAlert('请输入邮箱地址！', '请注意');
			     return false;
                     }
			value = $("#txtemail").attr("value");
			var EmailStr = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
		   if(!EmailStr.test(value)){
           hiAlert('邮箱地址错误,格式为:emailname@163.com！', '请注意');
			  return false;
                         }
       if( $("#txtVarifyID").attr("value")=="" ){
				  hiAlert('请输入验证码！', '请注意');
			     return false;
                   }

		 var queryString = "";
  		 queryString+= "email=";
       queryString+=value;
  		 queryString+= "&securitycode=";
       queryString+=$("#txtVarifyID").attr("value");
       
       alert(queryString);
       
		 $.post("eforgotpassword.php",queryString,function(msg){
							
						    if(msg==3){
                         // alert('验证码错误');
								 	hiAlert('验证码错误！', '请注意');
								 	return false;	
                                                           }	
                else if(msg==2){
                         // alert('验证码错误');
								 	hiAlert('帐号未激活,请到邮箱激活帐号！', '请注意');	
								 	return false;	
                                                           }
                else if(msg==0){
                         // alert('验证码错误');
								 	hiAlert('邮箱帐号不存在！', '请注意');	
								 	return false;	
                                                           }
                else if(msg==1){
                         // alert('验证码错误');
								 	hiAlert('请到您的邮箱中获取特别通道！', '请注意');	
								 	return true;	
                                                           }
                  });
}